package com.jbit.userserver.service.impl;

import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.jbit.userserver.mapper.TenantMapper;
import com.jbit.userserver.model.entity.Tenant;
import com.jbit.userserver.model.entity.User;
import com.jbit.userserver.service.TenantService;
import com.jbit.userserver.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Service
public class TenantServiceImpl implements TenantService {
    @Resource
    private UserService userService;
    @Resource
    private TenantMapper tenantMapper;
    @Override
    public Tenant getTenantByToken(HttpServletRequest request) {
        User user = userService.getUserByToken(request);
        return getTenantById(user.getTenantId());
    }

    @Override
    public Tenant getTenantById(Integer id) {
        MPJLambdaWrapper<Tenant> lambdaWrapper = new MPJLambdaWrapper();
        lambdaWrapper.eq(Tenant::getTenantId,id);
        return tenantMapper.selectOne(lambdaWrapper);
    }
}
